from flask import *
from models import db, User  # 导入 User 模型
from app import app  # 导入 app
def get_user_list():
    """
    查询所有用户的用户名和密码
    """
    with db.session.begin():  # 确保在数据库会话中执行
        users = User.query.all()  # 查询所有用户
        with open("user_list.txt", "w") as f:
            for user in users:
                f.write(f"username: {user.username}, password: {user.password}\n")
    return 0  # 返回用户信息列表

if __name__ == '__main__':
    with app.app_context():
        db.create_all()  # 创建所有表
        get_user_list()
